//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.domain.TestFile;
import com.ruoyi.system.domain.ToolFile;
import com.ruoyi.system.domain.vo.QuestionVo;
import com.ruoyi.system.service.ITestFileService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"/question"})
public class TestFileController extends BaseController {
    @Autowired
    private ITestFileService testFileService;
    @Autowired
    private TokenService tokenService;

    public TestFileController() {
    }

    @RequiresPermissions({"question:manage:add"})
    @PostMapping({"/uploadFile"})
    public String uploadFile(@RequestBody List<QuestionVo> fileVos) {
        return this.testFileService.testFileUpload(fileVos);
    }

    @PostMapping({"/list"})
    @RequiresPermissions({"question:manage:list"})
    public TableDataInfo list(@RequestBody TestFile file) {
        PageDomain pageDomain = new PageDomain();
        SysUser sysUser = this.tokenService.getLoginUser().getSysUser();
        if (StringUtils.isBlank(file.getOrgNo())) {
            file.setOrgNo(sysUser.getOrgNo());
        }

        BeanUtils.copyProperties(file, pageDomain);
        this.startPage(pageDomain);
        List<TestFile> list = this.testFileService.selectTestFileList(file);
        return this.getDataTable(list);
    }

    @PostMapping({"/add"})
    public AjaxResult add(@RequestBody JSONObject jsonString) {
        QuestionVo questionVo = (QuestionVo)JSONObject.parseObject(String.valueOf(jsonString), QuestionVo.class);
        return this.toAjax(this.testFileService.insertTestFile(questionVo));
    }

    @PostMapping({"/info"})
    @RequiresPermissions({"question:manage:query"})
    public AjaxResult getInfo(@RequestParam("fileId") String fileId) {
        return AjaxResult.success(this.testFileService.selectTestFileByFileId(fileId));
    }

    @PostMapping({"/update"})
    public AjaxResult update(@RequestBody ToolFile file) {
        return this.toAjax(this.testFileService.updateTestFile(file));
    }

    @GetMapping({"/remove"})
    @RequiresPermissions({"question:manage:remove"})
    public AjaxResult remove(@RequestParam("ids") String ids) {
        return AjaxResult.success(this.testFileService.deleteTestFileByIds(ids));
    }
}
